#ifndef __LOGGER_HPP__
#define __LOGGER_HPP__

#include <string>
#include <sstream>
#include <iostream>
#include <time.h>

/**
 * Convenience function for Logger::Log
 */
#define LOGSTRM(lvl, stream)			{ std::stringstream Strm; Strm << stream; Logger::log(lvl, Strm); }

/**
 * Prints log messages on stderr
 */
class Logger {

	public:
		/**
		 * Urgency level
		 */
		enum LogLevel { DEBUG, INFO, WARNING, ERROR };

		/**
		 * Print out a log message of specified urgency level
		 */
		static void log(LogLevel level, const std::string& str) {
			char buffer[32];
			time_t time_;
			time(&time_);
			strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localtime(&time_));

			std::cerr << buffer << " [" << logLevelStr(level) << "]: " << str << std::endl;
		}

		/**
		 * Print out a log message of specified urgency level
		 */
		static void log(LogLevel Level, const std::stringstream& Strm) {
			Logger::log(Level, Strm.str());
		}

	protected:
		/**
		 * Logger only provides static methods; don't allow creating an instance
		 */
		Logger() {
		}

		/**
		 * Returns string representation of urgency level
		 */
		static const char* logLevelStr(LogLevel level) {
			switch (level) {
				case DEBUG: return "DEBUG";
				case INFO: return "INFO";
				case WARNING: return "WARNING";
				case ERROR: return "ERROR";
			}
			return "INVALID";
		}

};
#endif

